//
//  ICMRepairPartsModel.m
//  ICrEAM
//
//  Created by FoREVer_SaD on 16/10/28.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMRepairPartsModel.h"
#import "ICMMaintenanceAndPartsView.h"
#import "ICMAppointmentMaintenanceAndPartsView.h"

@implementation ICMRepairPartsModel

-(BOOL)isDiscount{
    if ([self.IS_DISCOUNT isEqualToString:@"12781001"]) {
        return NO;
    }else{
        return YES;
    }
}

//- (NSString *)OEM_TAG{
//    return self.PART_SORT;
//}

//- (NSString *)PART_SALES_PRICE{
//    return self.SALE_PRICE;
//}

- (void)setSALE_PRICE:(NSString *)SALES_PRICE{
    _SALES_PRICE = SALES_PRICE;
    double price = [SALES_PRICE doubleValue]*100;
    double quantity = [_OBLIGATED_QUANTITY doubleValue]*100;
    double totalPrice = price*quantity/10000.0;
    if (price != 0 && quantity !=0) {
        _PART_SALES_AMOUNT = [NSString stringWithFormat:@"%.2lf", totalPrice];
    }
}

- (void)setOBLIGATED_QUANTITY:(NSString *)OBLIGATED_QUANTITY{
    _OBLIGATED_QUANTITY = OBLIGATED_QUANTITY;
    double price = [_SALES_PRICE doubleValue]*100;
    double quantity = [OBLIGATED_QUANTITY doubleValue]*100;
    double totalPrice = price*quantity/10000.0;
    if (price != 0 && quantity !=0) {
        _PART_SALES_AMOUNT = [NSString stringWithFormat:@"%.2lf", totalPrice];
    }
}

- (void)setDISCOUNT:(float)DISCOUNT{
    if (self.isDiscount) {
        _DISCOUNT = DISCOUNT;
    } else {
        _DISCOUNT = 1.0;
    }
    double price = [self.PART_SALES_AMOUNT doubleValue]*100;
    double ratioPrice = price*_DISCOUNT/100.0;
    self.DISCOUNT_AMOUNT = [NSString stringWithFormat:@"%.2lf", ratioPrice];
}

- (NSString *)REPAIR_TYPE_CODE{
    return [ICrEAMTool getRepiarTypeCodeWithRepiarName:_REPAIR_TYPE_NAME];
}


@end

@implementation ICMRepairPartsArrayModel

- (void)setupRepairPartsArrayModelWithPartsView:(ICMMaintenanceAndPartsView *)partsView{
    [partsView.repairPartsArray addObjectsFromArray:partsView.delRepairPartsArray];
    [partsView.delRepairPartsArray removeAllObjects];
    self.TT_RECPTION_PART = partsView.repairPartsArray;
}

- (void)setupRepairPartsArrayModelWithWithArray:(NSArray *)array{
    self.TT_RECPTION_PART = [array mutableCopy];
}

- (void)setupRepairPartsArrayModelWithAppointmentPartsView:(ICMAppointmentMaintenanceAndPartsView *)partsView{
    [partsView.repairPartsArray addObjectsFromArray:partsView.delRepairPartsArray];
    [partsView.delRepairPartsArray removeAllObjects];
    self.TT_BOOKING_ORDER_PART = partsView.repairPartsArray;
}

- (void)setupRepairPartsArrayModelWithRoPartsView:(ICMProxyMaintenanceAndPartsView *)partsView
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObjectsFromArray:partsView.repairPartsArray];
    [array addObjectsFromArray:partsView.delRepairPartsArray];
    self.TT_RO_REPAIR_PART = array;
}

- (void)createRepairPartsModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_RECPTION_PART) {
        ICMRepairPartsModel *model = [ICMRepairPartsModel yy_modelWithDictionary:dic];
        [array addObject:model];
    }
    self.TT_RECPTION_PART = array;
}

- (void)createRepairPartsBookingModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_BOOKING_ORDER_PART) {
        ICMRepairPartsModel *model = [ICMRepairPartsModel yy_modelWithDictionary:dic];
        [array addObject:model];
    }
    self.TT_BOOKING_ORDER_PART = array;
}

- (void)createRepairPartsRoModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_RO_REPAIR_PART) {
        ICMRepairPartsModel *model = [ICMRepairPartsModel yy_modelWithDictionary:dic];
        [array addObject:model];
    }
    self.TT_RO_REPAIR_PART = array;
}

@end







